<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"     uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<style>
#sa_table {text-align:center;border:1px solid #ddd; border-width:0 0 1px 1px;}

#sa_table th {background:#CCEEFF;}
#sa_table th,#sa_table td {height:22px; border:1px solid #ddd; border-width:1px 1px 0 0;}
</style>

<script type="text/javascript">
<!--
	function addAirSa(){
			window.location.href = "./SaMgr_create.do?saType=air";
	}
	
	function addOceanSa(){
		window.location.href = "./SaMgr_create.do?saType=ocean";
	}
//-->
</script>
<fmt:setLocale value="en_US"/> 
<div style="background-color:#F5F5F5;margin-top:1cm;">
	<input id="offset" type="hidden"  value="${pm.offset}">
	<div align="left">
		<s:actionmessage cssStyle="color:#0000FF;"/>
		<s:actionerror cssStyle="color:#F00;"/>
	</div>
	
	<c:if test="${searchUnRead != true}">
		<s:form id="search_from" action="SaMgr_search" validate="false">
			<table width="100%" height="60">
				<tr>
					<td align="right" width="10%" class="label_bold" >
					   <s:text name="sa.saNo"/>:
					</td>
					<td align="left"  width="10%">
						<s:textfield name="saNo" size="15"/>
					</td>
					<td align="right" width="10%" class="label_bold">
					   <s:text name="SA Type"/>:
					</td>
					<td align="left"  width="10%">
						<s:select id="saType" name="saType" list="saTypeList"/>
					</td>
					<td align="right"  width="10%" class="label_bold"> 
						<s:text name="sa.isPendding"/>:
					</td>
					<td align="left" width="10%">
						<s:select name="isPendding" list="penddingStatus"/>
					</td>
					<td align="left" width="25%">
						<s:submit key="action.search" action="SaMgr_search" cssClass="btn"/>
						<input class="btn" type="button" value="create AS" onclick="addAirSa()">
						<input class="btn" type="button" value="create OS" onclick="addOceanSa()">
					</td>
				</tr>
			</table>
		</s:form>
	</c:if>
	
	<table id="sa_table" width="100%" id="sa" >
		<thead>
			<tr class="ui-widget-header">
				<th style="width: 15%;">SA Number</th>
				<th style="width: 5%;">Dep</th>
				<s:if test="saType == 'air'">
					<th style="width: 5%;">DES</th>
				</s:if>
				<s:if test="saType == 'ocean'">
					<th style="width: 5%;">PORT</th>
				</s:if>
				
				<th style="width: 5%;">PCS</th>
				<th style="width: 5%;">Weight</th>
				<th style="width: 10%;">VOL</th>
				<th style="width: 10%;">ETA W/H</th>
				
				<s:if test="saType == 'air'">
					<th style="width: 15%;">Flight No</th>
				</s:if>
				<s:if test="saType == 'ocean'">
					<th style="width: 15%;">VESSEL NO</th>
				</s:if>
				
				<s:if test="saType == 'air'">
					<th style="width: 15%;">Flight Date</th>
				</s:if>
				<s:if test="saType == 'ocean'">
					<th style="width: 15%;">VESSEL DATE</th>
				</s:if>
				
				<s:if test="saType == 'air'">
					<th style="width: 15%;">MAWB</th>
				</s:if>
				<s:if test="saType == 'ocean'">
					<th style="width: 15%;">B/L NO</th>
				</s:if>
				
				<th style="width:5%;">State</th>
			</tr>
		</thead>
		<tbody >
			<c:forEach var="eachSa" items="${pm.datas}">
				<tr >
					<td align="left">
					   <a href="SaMgr_editSa.do?editSaId=${eachSa.id}">${eachSa.saNo}</a>
					   
					   <c:if test="${eachSa.saType == 'air'}">
					   	 A
					   </c:if>
					    <c:if test="${eachSa.saType == 'ocean'}">
					   	O
					   </c:if>
						
					   <c:if test="${eachSa.haveNewMsg == true}">
							<img style="border-width: 0" src="<%=request.getContextPath() %>/img/attached.gif">
						</c:if>
					</td>
					<td>${eachSa.gatway.name}</td>
					
					<s:if test="saType == 'air'">
						<td>${eachSa.destination}</td>
					</s:if>
					<s:if test="saType == 'ocean'">
						<td>${eachSa.portOfLoading}</td>
					</s:if>
					
					
					<td><fmt:formatNumber pattern="###" value="${eachSa.pcb}"></fmt:formatNumber></td>
					<td><fmt:formatNumber pattern="###" value="${eachSa.weight}"/></td>
					<td><fmt:formatNumber pattern="###" value="${eachSa.vweight}"/></td>
					<td>
					 	<fmt:formatDate value="${eachSa.estimatedTimeArrival}" />
					</td>
					
					
					<s:if test="saType == 'air'">
						<td>${eachSa.flightNo}</td>
					</s:if>
					<s:if test="saType == 'ocean'">
						<td>${eachSa.vesselVoyageNo}</td>
					</s:if>
					
					<s:if test="saType == 'air'">
						<td><fmt:formatDate value= "${eachSa.flightDate}" /></td>
					</s:if>
					<s:if test="saType == 'ocean'">
						<td><fmt:formatDate value= "${eachSa.vesselDate}" /></td>
					</s:if>
					
					<s:if test="saType == 'air'">
						<td>${eachSa.mawbNo}</td>
					</s:if>
					<s:if test="saType == 'ocean'">
						<td>${eachSa.blNo}</td>
					</s:if>	
					
					<td>${eachSa.stateShow}</td>
				</tr>
			</c:forEach>
			</tbody>
	</table>
	<s:include value="./component/result_empty.jsp"></s:include>
</div>
<div align="left">
 	<pg:pager url="${searchUrl}" items="${pm.total}" maxPageItems="${pm.maxPageItems}" export="currentPageNumber=pageNumber">  
	<pg:param name="saNo"/>
	<pg:param name="saType"/>
	<pg:param name="userId"/>
	<pg:page export="firstItem, lastItem">
		<div class="resultInfo">
			Displaying results <strong><%= firstItem %>-<%= lastItem %></strong> of <strong>${pm.total}</strong> found
		</div>
	</pg:page>
	
	<div class="rnav">
		<span class="rnavLabel">Results:</span>&nbsp;
		<pg:prev export="pageUrl">
			<a href="<%= pageUrl %>" class="rnavLink">&#171;&nbsp;Prev</a>&nbsp;
		</pg:prev>
		<pg:pages export="pageUrl,pageNumber,firstItem,lastItem">
		    <% if (pageNumber == currentPageNumber) { %> 
		&nbsp;<span class="rnavCurr"><%= firstItem %>-<%= lastItem %></span>
		    <% } else { %>
		&nbsp;<a href="<%= pageUrl %>" class="rnavLink"><%= firstItem %>-<%= lastItem %></a>
		    <% } %>
		</pg:pages>
		<pg:next export="pageUrl">
			&nbsp;&nbsp;<a href="<%= pageUrl %>" class="rnavLink">Next&nbsp;&#187;</a>
		</pg:next>
	</div>
 	 </pg:pager>
</div>